﻿using System;
using System.IO;
using System.Text;
using System.Windows;

namespace AutoDeployForSims.From18To10Cfg.Utility
{
    public class WriteTXT
    {
        /// <summary>
        /// 创建带有日期时间戳的txt文件并写入
        /// </summary>
        /// <param name="path">txt文件保存路径</param>
        /// <param name="content">文档内容</param>
        public static void WriteWithDate(string path, string content)
        {
            string date = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
            //文件名
            string fileName = "test-" + date + ".txt";

            try
            {
                File.WriteAllText(Path.Combine(path, fileName), content, Encoding.Default);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        /// <summary>
        /// 写入txt文件，文件存在则追加入也已有文件
        /// </summary>
        /// <param name="txtPath">txt文件的路径</param>
        /// <param name="content">内容</param>
        public static void WriteToTXT(string txtPath, string content)
        {
            try
            {
                File.AppendAllText(txtPath, content, Encoding.Default);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

    }
}
